<template>
  <div class="common-layout">
    <el-container>
      <el-header>
        <div>
          <!-- 添加logo -->
          <img src="../assets/navlogo.png">
          <span>XXX电商后台系统</span>
        </div>
        <div>
          <el-button @click="logout">注销</el-button>
        </div>
      </el-header>
      <el-container>
        <el-aside width="200px">
          <el-menu
              active-text-color="#ffd04b"
              background-color="#545c64"
              class="el-menu-vertical-demo"
              :default-active="activePath"
              text-color="#fff"
              @open="handleOpen"
              @close="handleClose"
              :router="true"
              :unique-opened="true"
              @select="selectFun"
          >
            <el-sub-menu index="1">
              <template #title>
                <el-icon>
                  <location/>
                </el-icon>
                <span>用户管理</span>
              </template>
              <el-menu-item index="/index/userlist">用户列表</el-menu-item>
              <el-menu-item index="1-2">用户添加</el-menu-item>
              <el-menu-item index="1-2">用户修改</el-menu-item>
            </el-sub-menu>
            <el-sub-menu index="2">
              <template #title>
                <el-icon>
                  <Document/>
                </el-icon>
                <span>角色管理</span>
              </template>
              <el-menu-item index="2-1">角色列表</el-menu-item>
              <el-menu-item index="2-2">角色添加</el-menu-item>
              <el-menu-item index="2-2">角色修改</el-menu-item>
            </el-sub-menu>
            <el-sub-menu index="3">
              <template #title>
                <el-icon>
                  <Document/>
                </el-icon>
                <span>支付管理</span>
              </template>
              <el-menu-item index="/index/pay">支付列表</el-menu-item>
            </el-sub-menu>
          </el-menu>
        </el-aside>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>

import {ElMessage, ElMessageBox} from 'element-plus'

import {
  Document,
  Menu as IconMenu,
  Location,
  Setting,
} from '@element-plus/icons-vue'

export default {
  name: "Index",
  data(){
    return {
      activePath: '/index/welcome'
    }
  },
  methods: {
    selectFun(path){
      console.log(path);
      this.activePath = path;
    },
    handleOpen(key, keyPath){
      console.log(key);
      console.log(keyPath);
    },
    handleClose(key, keyPath){
      console.log(key);
      console.log(keyPath);
    },
    // 注销
    logout() {
      ElMessageBox.confirm(
          '您确认注销当前登录吗?',
          '注销',
          {
            confirmButtonText: '确认',
            cancelButtonText: '取消',
            type: 'warning',
          }
      ).then(() => {
        ElMessage({
          type: 'success',
          message: '注销成功',
        });
        // 将sessionStorage中的token清除
        sessionStorage.removeItem("token");
        // 跳转到登录页面
        window.location.href = '/login';
      })
          .catch(() => {
            ElMessage({
              type: 'info',
              message: '取消注销',
            })
          })
    }
  }
}
</script>

<style scoped>
.common-layout {
  width: 100%;
  height: 100%;
}

.el-container {
  width: 100%;
  height: 100%;
}

.el-container > .el-header {
  height: 10%;
  width: 100%;
  background-color: #545c64;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.el-container > .el-header > div {
  display: flex;
  align-items: center;
}

.el-container > .el-header > div > img {
  border-radius: 50%;
}

.el-container > .el-header > div > span {
  margin-left: 15px;
}

.el-container > .el-aside {
  width: 200px;
  height: 100%;
  background-color: #545c64;
}

.el-container > .el-aside > .el-menu {
  height: 100%;
}

.el-container > .el-main {
}
</style>